package com.yxdj.feedback.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yxdj.common.core.web.controller.BaseController;
import com.yxdj.common.core.web.domain.AjaxResult;
import com.yxdj.common.core.web.page.TableDataInfo;
import com.yxdj.common.log.annotation.Log;
import com.yxdj.common.log.enums.BusinessType;
import com.yxdj.common.security.annotation.RequiresPermissions;
import com.yxdj.feedback.api.domain.Tag;
import com.yxdj.feedback.service.TagService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标签管理
 */
@io.swagger.v3.oas.annotations.tags.Tag(name = "标签管理")
@RestController
@RequestMapping("/tag")
public class TagController extends BaseController {

    @Autowired
    private TagService tagService;


    /**
     * 分页获取标签列表
     */
    @Operation(summary = "分页获取标签列表")
    @GetMapping("/list")
    public TableDataInfo list(Tag tag) {
        startPage();
        List<Tag> list = tagService.list(new LambdaQueryWrapper<Tag>().like(tag.getName() != null, Tag::getName, tag.getName()));
        return getDataTable(list);
    }

    /**
     * 获取标签详细信息
     */
    @Operation(summary = "获取标签详细信息")
    @GetMapping(value = "/getById/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(tagService.getById(id));
    }

    /**
     * 新增标签
     */
    @Operation(summary = "新增标签")
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tag tag) {
        return toAjax(tagService.save(tag));
    }

    /**
     * 修改标签
     */
    @Operation(summary = "修改标签")
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tag tag) {
        return toAjax(tagService.updateById(tag));
    }

    /**
     * 删除标签
     */
    @Operation(summary = "删除标签")
    @RequiresPermissions("system:tag:remove")
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(tagService.removeByIds(ids));
    }
}
